import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

const dashboard = resolve => require(['../views/dashboard/index'], resolve);

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
	// {
	// 	path: '/redirect',
	// 	component: Layout,
	// 	hidden: true,
	// 	children: [
	// 		{
	// 			path: '/redirect/:path(.*)',
	// 			component: () => import('@/views/redirect/index')
	// 		}
	// 	]
	// },

	{
		path: '/login',
		component: () => import('@/views/login/index'),
		hidden: true
	},

	{
		path: '/404',
		component: () => import('@/views/404'),
		hidden: true
	},

	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		children: [{
			path: 'dashboard',
			name: '首页',
			component: dashboard,
			meta: { title: '首页', icon: 'dashboard' }
		}]
	},

	{
		path: '/message',
		component: Layout,
		children: [
			{
				path: 'index',
				name: '消息与通知',
				component: () => import('@/views/message'),
				meta: { title: '消息与通知', icon: 'table' }
			}
		]
	}
]

export const asyncRoutes = [
	{
		path: '/province/userManage',
		component: Layout,
		children: [
			{
				path: 'index',
				name: '用户管理',
				component: () => import('@/views/userManage'),
				meta: { title: '用户管理', icon: 'table', role: 5 }
			}
		]
	},

	{
		path: '/province/roleManage',
		component: Layout,
		children: [
			{
				path: 'index',
				name: '角色管理',
				component: () => import('@/views/roleManage'),
				meta: { title: '角色管理', icon: 'table', role: 6 }
			}
		]
	},

	{
		path: '/province/investigationManage',
		component: Layout,
		redirect: '/province/investigationManage/investigationPeriod',
		name: "调查期管理",
		meta: { title: '调查期管理', icon: 'table', role: 7 },
		children: [
			{
				path: 'investigationPeriod',
				name: '调查期',
				component: () => import('@/views/investigationManage/investigationPeriod'),
				meta: { title: '调查期', icon: 'table' }
			},
			{
				path: 'investigationPattern',
				name: '调查期模式',
				component: () => import('@/views/investigationManage/investigationPattern'),
				meta: { title: '调查期模式', icon: 'table' }
			},
		]
	},

	{
		path: '/enterprise/enterpriseRecord',
		component: Layout,
		redirect: '/enterprise/enterpriseRecord/enterpriseRecordSubmit',
		name: "企业备案",
		meta: { title: '企业备案', icon: 'form', role: 1 },
		children: [
			{
				path: 'enterpriseRecordSubmit',
				name: '上报备案信息',
				component: () => import('@/views/enterpriseRecord/enterpriseRecordSubmit'),
				meta: { title: '上报备案信息', icon: 'form' }
			},

			{
				path: 'enterpriseInformation',
				name: '企业信息',
				component: () => import('@/views/enterpriseRecord/enterpriseInformation'),
				meta: { title: '企业信息', icon: 'form' }
			}
		]
	},

	{
		path: '/province/examine',
		name: '审核',
		component: Layout,
		meta: { title: '审核', icon: 'table' },
		children: [
			{
				path: 'dataFormExamine',
				name: '数据审核',
				component: () => import('@/views/examine/dataFormExamine'),
				meta: { title: '数据审核', icon: 'table', role: 4 }
			},
			{
				path: 'recordExamine',
				name: '备案审核',
				component: () => import('@/views/examine/recordExamine'),
				meta: { title: '备案审核', icon: 'table', role: 3 }
			}
		]
	},

	{
		path: '/enterprise/dataFilling',
		component: Layout,
		children: [
			{
				path: 'index',
				name: '数据填报',
				component: () => import('@/views/dataFilling'),
				meta: { title: '数据填报', icon: 'table', role: 2 }
			}
		]
	},

	{
		path: '/enterprise/dataQuery',
		component: Layout,
		children: [
			{
				path: 'index',
				name: '数据查询',
				component: () => import('@/views/dataQuery'),
				// TODO: 暂时与备案共用权限
				meta: { title: '数据查询', icon: 'table', role: 1 }
			}
		]
	},

	{
		path: '/province/provinceDataQuery',
		component: Layout,
		name: '查询',
		meta: { title: '企业信息查询', icon: 'table'},
		children: [
			{
				path: 'formQuery',
				name: '报表查询',
				component: () => import('@/views/provinceDataQuery/formQuery'),
				meta: { title: '报表查询', icon: 'table', role: 10 }
			},
			{
				path: 'filingInfoQuery',
				name: '备案信息查询',
				component: () => import('@/views/provinceDataQuery/filingInfoQuery'),
				meta: { title: '备案信息查询', icon: 'table', role: 9 }
			}
		]
	},

	{
		path: '/province/dataVisualization',
		component: Layout,
		redirect: '/province/dataVisualization/index',
		meta: { title: '查看统计数据', icon: 'dashboard', role: 8 },
		name: "查看统计数据",
		children: [
			{
				path: 'index',
				name: '企业数量信息统计',
				component: () => import('@/views/dataVisualization/index'),
				meta: { title: '企业数量信息统计', icon: 'dashboard' }
			},

			{
				path: 'compare',
				name: '就业情况对比分析',
				component: () => import('@/views/dataVisualization/compare'),
				meta: { title: '就业情况对比分析', icon: 'dashboard' }
			},

			{
				path: 'tendency',
				name: '就业情况趋势分析',
				component: () => import('@/views/dataVisualization/tendency'),
				meta: { title: '就业情况趋势分析', icon: 'dashboard' }
			},

			{
				path: 'multiDimension',
				name: '就业情况多维分析',
				component: () => import('@/views/dataVisualization/multiDimension'),
				meta: { title: '就业情况多维分析', icon: 'dashboard' }
			},
		]
	},

	// 404 page must be placed at the end !!!
	{ path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({ y: 0 }),
	routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
